/* ************************************************************
	File:        /fabridge_example01/assets/js/fabridge_example01.js
	Author:      Brice Mason
	Description: Used to run the various demonstrations of the FABridge example.
	
	Revision History:
		2007-06-13 bmason - Creation date.
		
	Copyright (c) 2007 by Brice Mason
	http://www.skipslate.com
	No warranty. Commerical and non-commerical use freely permitted.
************************************************************ */

// global variable
var flexApp;

var initCallback = function() {
	flexApp = FABridge.flex.root();
	return;
}
// register the callback to our Flex application with the 'bridgeName' of 'flex'
FABridge.addInitializationCallback( "flex", initCallback );

// step 5 - get objects by ID
function getId() {
	var swfObj_mainDish = flexApp.getTxt_mainDish();
	alert( "Got the object, it's ID is '" + swfObj_mainDish.getId() + "'" );
	
	return;
}

// step 6 - get object properties
function getProperty() {
	// get the 'mainDish' object
	var swfObj_mainDish = flexApp.getTxt_mainDish();
	// show what's for dinner
	alert( "Delicious, we're having " + swfObj_mainDish.getText() + " for dinner!" );
	
	return;
}

// step 7 - set object properties
function setProperty() {
	// there's a special tonight
	var str_special = "cheeseburgers";
	// get the 'main dish' object
	var swfObj_mainDish = flexApp.getTxt_mainDish();
	// what's the main dish?
	alert( "We currently offer " + swfObj_mainDish.getText() + "." );
	// switch it up, we'll have the special.
	swfObj_mainDish.setText( str_special );
	alert( "I changed my mind, I'm having the special which is " + swfObj_mainDish.getText() + "." );
	
	return;
}

// step 8 - call object methods
function callObjectMethod() {
	// get the 'main dish' object
	var swfObj_mainDish = flexApp.getTxt_mainDish();
	// set focus to the 'main dish' TextInput
	swfObj_mainDish.setFocus();
	// select some text in the 'main dish' TextInput
	swfObj_mainDish.setSelection( 1, 2 );
	
	return;
}

// step 9 - attach event handler
function attachEvent() {
	// get the 'main dish' object
	var swfObj_mainDish = flexApp.getTxt_mainDish();

	// define a function used as a callback to JavaScript
	var mainDishCallback = function( event ) {
		// get the object which fired the event
		var swfObj_source = event.getTarget();
		// as the value in the swf 'main dish' changes, so does the html 'main dish'
		document.frm_mainMenu.frm_mainDish.value = swfObj_source.getText();
		
		return;
	}
	swfObj_mainDish.addEventListener( "change", mainDishCallback );
	
	return;
}